package de.hsmannheim.poolraumapp.model.fetcher;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;

import org.joda.time.DateTime;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import de.hsmannheim.poolraumapp.model.Rooms;
import de.hsmannheim.poolraumapp.util.DateTimeTypeConverter;

public class RoomFetcher {
	private static final String TAG = RoomFetcher.class.getName();	
	private InputStream src;
	
	public RoomFetcher(InputStream src) {
		this.src = src;
	}
	
	public Rooms fetch() {
		Gson gson = new GsonBuilder()
			.registerTypeAdapter(DateTime.class, new DateTimeTypeConverter())
			.create();
		Rooms rooms = gson.fromJson(new InputStreamReader(src, Charset.forName("UTF-8")), Rooms.class);
		return rooms;
	}
}
